﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.Design;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace ODataSource
{
    public class ODataSourceDesigner : DataSourceDesigner
    {
        private ODataSource _control;
        private string _defaultViewName = "";
        private ODesignDataSourceView _view = null;

        // Initialize the designer
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            _control = (ODataSource)Component;
        }

        // Get a view
        public override DesignerDataSourceView GetView(string viewName)
        {
            if (!viewName.Equals(_defaultViewName))
                return null;

            if (_view == null)
            {
                _view = new ODesignDataSourceView(this,
                    _defaultViewName);
            }

            return _view;
        }

        // Get a list of view names
        public override string[] GetViewNames()
        {
            return new string[] { "" };
        }

        // Do not allow refreshing the schema
        public override bool CanRefreshSchema
        {
            get { return true; }
        }
        // Do not allow resizing
        public override bool AllowResize
        {
            get { return false; }
        }

        public ODataSource Control
        {
            get { return _control; }
        }

        public override bool CanConfigure
        {
            get
            {
                return false;
            }
        }

        public override void  RefreshSchema(bool preferSilent)
        {
            this._view._data = null;
           
        }
    }
}
